/*
 * @Description: Response uniform process
 * @Author: Jinzhu Liu
 * @Date: 2021-12-15 23:48:14
 * @LastEditor: Jinzhu Liu
 * @LastEditTime: 2021-12-22 23:59:09
 */

import { Context } from "koa";
/**
 * @description: Success function
 * @param {Context} ctx
 * @param {*} data
 * @param {string} msg
 * @param {number} code
 */
function success<T>(
    ctx: Context,
    data: any = null,
    msg: string = 'success', 
    code: number = 0
) {
    ctx.body = {
        code,
        msg,
        data
    }
}

/**
 * @description: Error function
 * @param {Context} ctx
 * @param {[]} data Extend info
 * @param {string} msg error message
 * @param {number} code status code
 */
function error(
    ctx: Context,
    msg: string = 'error',
    data: any = null,
    code: number = 1
) {
    ctx.body = {
        code,
        msg,
        data
    }
}

export default {
    success,
    error
}
